package com.sumi.erp.controller;

import com.sumi.common.annotation.Log;
import com.sumi.common.core.controller.BaseController;
import com.sumi.common.core.domain.AjaxResult;
import com.sumi.common.core.page.TableDataInfo;
import com.sumi.common.enums.BusinessType;
import com.sumi.common.utils.poi.ExcelUtil;
import com.sumi.erp.domain.FinanceSaleReceipt;
import com.sumi.erp.service.IFinanceSaleReceiptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 收款单Controller
 * 
 * @author fgf67@163.com
 * @date 2024-06-28
 */
@RestController
@RequestMapping("/erp/receipt")
public class FinanceSaleReceiptController extends BaseController
{
    @Autowired
    private IFinanceSaleReceiptService financeSaleReceiptService;

    /**
     * 查询收款单列表
     */
    @PreAuthorize("@ss.hasPermi('erp:receipt:list')")
    @GetMapping("/list")
    public TableDataInfo list(FinanceSaleReceipt financeSaleReceipt)
    {
        startPage();
        List<FinanceSaleReceipt> list = financeSaleReceiptService.selectFinanceSaleReceiptList(financeSaleReceipt);
        return getDataTable(list);
    }

    /**
     * 导出收款单列表
     */
    @PreAuthorize("@ss.hasPermi('erp:receipt:export')")
    @Log(title = "收款单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FinanceSaleReceipt financeSaleReceipt)
    {
        List<FinanceSaleReceipt> list = financeSaleReceiptService.selectFinanceSaleReceiptList(financeSaleReceipt);
        ExcelUtil<FinanceSaleReceipt> util = new ExcelUtil<FinanceSaleReceipt>(FinanceSaleReceipt.class);
        util.exportExcel(response, list, "收款单数据");
    }

    /**
     * 获取收款单详细信息
     */
    @PreAuthorize("@ss.hasPermi('erp:receipt:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(financeSaleReceiptService.selectFinanceSaleReceiptById(id));
    }

    /**
     * 新增收款单
     */
    @PreAuthorize("@ss.hasPermi('erp:receipt:add')")
    @Log(title = "收款单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FinanceSaleReceipt financeSaleReceipt)
    {
        return toAjax(financeSaleReceiptService.insertFinanceSaleReceipt(financeSaleReceipt));
    }

    /**
     * 修改收款单
     */
    @PreAuthorize("@ss.hasPermi('erp:receipt:edit')")
    @Log(title = "收款单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FinanceSaleReceipt financeSaleReceipt)
    {
        return toAjax(financeSaleReceiptService.updateFinanceSaleReceipt(financeSaleReceipt));
    }

    /**
     * 删除收款单
     */
    @PreAuthorize("@ss.hasPermi('erp:receipt:remove')")
    @Log(title = "收款单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(financeSaleReceiptService.deleteFinanceSaleReceiptByIds(ids));
    }
}
